package com.zklh.leetcode.greedy.easy.problem455;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @ClassName Solution
 * @Description
 * @Author 坐看落花
 * @Date 2020/7/20 15:02
 * @Version 1.0
 **/
public class Solution {
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);

        int childIndex = 0;
        int cookieIndex = 0;

        while (childIndex < g.length && cookieIndex < s.length) {
            if (s[cookieIndex] >= g[childIndex]) {
                cookieIndex++;
                childIndex++;
            } else {
                cookieIndex++;
            }
        }

        return childIndex;
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        int[] g = new int[]{1,2,3};
        int[] s = new int[]{1,1};
        System.out.println(solution.findContentChildren(s,g ));
    }
}
